package com.fashion.web.actions;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Controller;

import com.fashion.model.gallery.Album;
import com.opensymphony.xwork2.ActionSupport;

//@Controller
//@Namespace("/gallery")
public class GalleryAction extends ActionSupport {
	static private String GALLERY_CATEGORY_TAG = "galleryCatagory";
	@Resource(name = "hibernateTemplate")
	private HibernateTemplate template;
	private List<Album> albumList;

	public void setTemplate(HibernateTemplate template) {
		this.template = template;
	}

	public List<Album> getAlbumList(){
		return albumList;
	}
	
//	@Action(value = "gallery", results = {@Result(name = SUCCESS, location = "gallery.jsp")})
	public String execute() throws Exception {
		String category = ServletActionContext.getRequest().getParameter(GALLERY_CATEGORY_TAG);
		albumList = template.find("from Album where category=?", category);
		return SUCCESS;
	}
}
